using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ServiceModel.DomainServices.Client;
using System.Windows.Input;
using AR.Entities;
using AR.Model;
using AR.ViewModels.Commands;

namespace AR.ViewModels
{
    public class HomeViewModel : ViewModelBase
    {
        private readonly CandidatModel model;
        private ObservableCollection<CANDIDAT> _candidats;
        public ObservableCollection<CANDIDAT> Candidats
        {
            get
            {
                return _candidats;
            }
            set
            {
                if (value != _candidats)
                {
                    _candidats = value;
                    OnPropertyChanged("Candidats");
                }
            }
        }
        private CANDIDAT _selectedCandidat;
        public CANDIDAT SelectedCandidat
        {
            get { return _selectedCandidat; }
            set
            {
                _selectedCandidat = value;
                OnPropertyChanged("SelectedCandidat");
            }
        }
        public HomeViewModel()
        {
              model = new CandidatModel();
              Candidats = new ObservableCollection<CANDIDAT>();
              model.GetCandidats().EntityAdded += OnEntityAdded;
                
        }
        private void OnEntityAdded(object sender,
                                  EntityCollectionChangedEventArgs<CANDIDAT> entityCollectionChangedEventArgs)
        {
           
            Candidats.Add(entityCollectionChangedEventArgs.Entity);
        }
        public ICommand SaveCandidatCommand
        {
            get
            {
                return new UpdateSelectedCandidat(this);
            }
        }
        public void SubmitChanges()
        {
            model.SubmitChanges();
        }
    }
}